package com.example.alphabetindexer.demo;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.alphabetindexer.R;
import com.example.alphabetindexer.widget.AlphabetIndexerAdapter;
import com.example.alphabetindexer.widget.AlphabetIndexerBean;

public class ContactAdapter extends AlphabetIndexerAdapter {
	private Context context;

	public ContactAdapter(Context context, List<AlphabetIndexerBean> contactList) {
		super();
		this.context = context;
		super.setBeanList(contactList);
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public Context getContext() {
		return context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.activity_contact_item,null);
		}

		final Contact contact = (Contact) beanList.get(position);

		TextView tvName = (TextView) convertView.findViewById(R.id.item_tvw_contact_name);
		TextView tvMobile = (TextView) convertView.findViewById(R.id.item_tvw_contact_num);
		TextView tvInvite = (TextView) convertView.findViewById(R.id.bt_tongxun);

		tvName.setText(contact.getName());
		tvMobile.setText(contact.getPhonenum());

		// 事件绑定
		tvMobile.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(context, contact.getPhonenum()+" clicked ", Toast.LENGTH_SHORT).show();
			}
		});
		
		tvInvite.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(context, " 添加 clicked ", Toast.LENGTH_SHORT).show();
			}
		});
		
		
		super.setItemTitle(convertView, position, R.id.tvSection);
		return convertView;
	}

}
